package com.bdd.crowd.service.impl;

import com.bdd.crowd.entity.Role;
import com.bdd.crowd.mapper.RoleMapper;
import com.bdd.crowd.service.api.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author banddong
 * @create 2020-09-12 22:26
 * Role(角色)接口实现类
 */
@Service
public class RoleServiceImpl implements RoleService {

    // 装配Mapper接口
    @Autowired
    private RoleMapper roleMapper;


    // 页面一览
    @Override
    public PageInfo<Role> getPageInfo(Integer pageNum, Integer pageSize, String keyword) {
        // 1.开启分页功能
        PageHelper.startPage(pageNum, pageSize);
        // 2.执行查询
        List<Role> roleList = roleMapper.selectRoleByKeyword(keyword);
        // 3.封装为pageInfo对象返回
        return new PageInfo<>(roleList);
    }

    // 新增
    @Override
    public void saveRole(Role role) {
        roleMapper.insert(role);
    }

    // 修改
    @Override
    public void updateRole(Role role) {
        roleMapper.updateByPrimaryKey(role);
    }
}
